fix restaging of transferred files after stalldetection kicks in
authorJoey Hess <joeyh@joeyh.name>
Fri, 23 Sep 2022 19:55:40 +0000 (15:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 23 Sep 2022 19:55:40 +0000 (15:55 -0400)
Sponsored-by: Dartmouth College's DANDI project
Annex/Link.hs
Annex/TransferrerPool.hs

index 0849993d19afec01ba4278d7be0fa32e3668ed8b..496a071535c9d5fb104970345457dc807383a808 100644 (file)
@@ -217,6 +217,8 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
        liftIO . Database.Keys.Handle.closeDbHandle
                =<< Annex.getRead Annex.keysdbhandle
        realindex <- liftIO $ Git.Index.currentIndexFile r
+       numsz@(numfiles, _) <- calcRestageLog (0, 0) $ \(_f, ic) (numfiles, sizefiles) ->
+               (numfiles+1, sizefiles + inodeCacheFileSize ic)
        let lock = fromRawFilePath (Git.Index.indexFileLock realindex)
            lockindex = liftIO $ catchMaybeIO $ Git.LockFile.openLock' lock
            unlockindex = liftIO . maybe noop Git.LockFile.closeLock
@@ -235,8 +237,6 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
                                [ Param "-c"
                                , Param $ "core.safecrlf=" ++ boolConfig False
                                ] }
-                       numsz <- calcRestageLog (0, 0) $ \(_f, ic) (numfiles, sizefiles) ->
-                               (numfiles+1, sizefiles + inodeCacheFileSize ic)
                        configfilterprocess numsz $ runsGitAnnexChildProcessViaGit' r'' $ \r''' ->
                                Git.UpdateIndex.refreshIndex r''' $ \feeder -> do
                                        let atend = do
@@ -251,7 +251,8 @@ restagePointerFiles r = unlessM (Annex.getState Annex.insmudgecleanfilter) $ do
                ok <- liftIO (createLinkOrCopy realindex tmpindex)
                        <&&> catchBoolIO updatetmpindex
                unless ok showwarning
-       bracket lockindex unlockindex go
+       when (numfiles > 0) $
+               bracket lockindex unlockindex go
   where
        isunmodified tsd f orig = 
                genInodeCache f tsd >>= return . \case
index b1046a959006a693eff70cb82068bbb25d63ca8f..a46617b3cbf62a7e02f3152d9b3c13a5385bf684 100644 (file)
@@ -1,6 +1,6 @@
 {- A pool of "git-annex transferrer" processes
  -
- - Copyright 2013-2021 Joey Hess <id@joeyh.name>
+ - Copyright 2013-2022 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -22,6 +22,7 @@ import Types.CleanupActions
 import Messages.Serialized
 import Annex.Path
 import Annex.StallDetection
+import Annex.Link
 import Utility.Batch
 import Utility.Metered
 import qualified Utility.SimpleProtocol as Proto
@@ -286,3 +287,10 @@ emptyTransferrerPool = do
        liftIO $ forM_ pool $ \case
                TransferrerPoolItem (Just t) _ -> transferrerShutdown t
                TransferrerPoolItem Nothing _ -> noop
+       -- Transferrers usually restage pointer files themselves,
+       -- but when killTransferrer is used, a transferrer may have
+       -- pointer files it has not gotten around to restaging yet.
+       -- So, restage pointer files here in clean up from such killed
+       -- transferrers.
+       unless (null pool) $
+               restagePointerFiles =<< Annex.gitRepo